from typing import *
from heapq import heappush, heapreplace


class Solution:

    def scheduleCourse(self, courses: List[List[int]]) -> int:
        courses.sort(key=lambda a: a[1])
        t = 0
        q = []
        for s, e in courses:
            if t + s <= e:
                t += s
                heappush(q, -s)
            elif q and -q[0] > s:
                t += q[0] + s
                heapreplace(q, -s)
        return len(q)


s = Solution()
print(s.scheduleCourse(courses=[[3, 2], [4, 3]]))


